package com.yckj.day09;

/**
 * TODO 测试
 *
 * @author shengyuee
 * @version 1.0
 * 2025/7/28 14:52
 */
public class AnimalTest {
    public static void main(String[] args) {
        // 多态形式, 向上转型
        Animal dog = new Dog();
        Animal dog22 = new Cat();
        System.out.println(dog22 instanceof Dog);
        // instanceof是运算符，判断dog对象是否属于Dog类型
        boolean flag = dog instanceof  Dog;
        System.out.println("flag = " + flag);
        if(flag){
            Dog dog2 = (Dog)dog; // 向下转型，强制转换
            dog2.lookHome();
        }else{
            System.out.println("类型转换异常");
        }
        Dog dog1 = new Dog();
        dog1.lookHome();
    }
}
